package com.zian.controller.user;


import cn.hutool.core.lang.tree.Tree;
import com.zian.common.R;
import com.zian.domain.dto.CategoryDTO;
import com.zian.domain.po.SysGoodsCategory;
import com.zian.domain.vo.CategoryVO;
import com.zian.service.ISysGoodsCategoryService;
import com.zian.validation.ValidGroup;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2024-09-08
 */
@Slf4j
@Api("商品分类接口")
@RestController("SysGoodsCategoryControllerUser")
@RequestMapping("/user/categorys")
@RequiredArgsConstructor
public class SysGoodsCategoryController {


    private final ISysGoodsCategoryService goodsCategoryService;

    @GetMapping("/list")
   @ApiOperation("查询商品分类")
    public R<List<Tree<Long>>> queryCategory() {
        log.info("查询商品");
        return R.ok(goodsCategoryService.queryCategory());
    }

    // 根据父级id获取子分类
    @GetMapping("/children/{id}")
   @ApiOperation("根据父级id获取子分类")
    public R<List<Tree<Long>>> getChildrenCategory(@PathVariable Long id) {
        log.info("根据父级id获取子分类：{}", id);
        List<Tree<Long>> list = goodsCategoryService.getChildrenCategory(id);
        return R.ok(list);
    }


    // 获取所有顶级分类
    @GetMapping("/top")
   @ApiOperation("获取所有顶级分类")
    public R<List<CategoryVO>> getTopCategory() {
        log.info("获取所有顶级分类");
        List<CategoryVO> list = goodsCategoryService.getTopCategory();
        return R.ok(list);
    }

}
